//
//  DataManager.swift
//  StoreProject
//
//  Created by CYC on 1998/12/30.
//

// 操作数据库

import UIKit
import GRDB

class DataManager: NSObject {
    
    
    // 数据库地址
    private static var dbPath: String = {
        let filePath: String = NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory, FileManager.SearchPathDomainMask.userDomainMask, true).first!.appending("/StoreProject.db")
        return filePath
    }()
    
    // 数据库配置
    private static var configuration: Configuration = {
        var configuration = Configuration()
        configuration.busyMode = Database.BusyMode.timeout(5.0)
        return configuration
    }()
    
    // 创建数据库
    static var dbQueue: DatabaseQueue = {
        let db = try! DatabaseQueue(path: DataManager.dbPath, configuration: DataManager.configuration)
        db.releaseMemory()
        return db
    }()
}
